package it.asvp.asvp_portal.data.entity.review;


import static javax.persistence.GenerationType.IDENTITY;
import it.asvp.asvp_portal.asvp_util.enumerative.ReviewType;
import it.asvp.asvp_portal.data.entity.domain.BaseEntity;
import it.asvp.asvp_portal.data.entity.member.Member;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "review", catalog = "asvp_db")
public class Review extends BaseEntity {

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	private Long id;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_member", nullable = false)
	private Member member;
	
	@Column(name = "review_type", nullable = false, length = 50)
	@Enumerated(EnumType.STRING)
	private ReviewType reviewType;
	
	@Column(name = "description", nullable = false, length = 1000)
	private String description;
	
	@Column(name = "title", nullable = false, length = 100)
	private String title;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "review")
	@Cascade({CascadeType.ALL})
	private Set<ReviewPicture> reviewPictures = new HashSet<ReviewPicture>(0);

	public Review() {
	}

	public Review(Member member, ReviewType reviewType, String description,
			String title, Date createdOn, Date lastUpdate,
			Set<ReviewPicture> reviewPictures) {
		this.member = member;
		this.reviewType = reviewType;
		this.description = description;
		this.title = title;
		this.createdOn = createdOn;
		this.lastUpdate = lastUpdate;
		this.reviewPictures = reviewPictures;
	}


	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	
	public Member getMember() {
		return this.member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	
	public ReviewType getReviewType() {
		return this.reviewType;
	}

	public void setReviewType(ReviewType reviewType) {
		this.reviewType = reviewType;
	}

	
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public Set<ReviewPicture> getReviewPictures() {
		return this.reviewPictures;
	}

	public void setReviewPictures(Set<ReviewPicture> reviewPictures) {
		this.reviewPictures = reviewPictures;
	}

}
